package com.example.myone.Util;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import java.util.Objects;

public class DrawableUtil {
    @SuppressLint("UseCompatLoadingForDrawables")
    private void setDrawableWithColorAndSize(Context context, TextView textView, int drawableResId, int colorResId) {
        // 获取当前颜色
        int color = ContextCompat.getColor(context, colorResId);
        // 设置字体颜色
        textView.setTextColor(color);
        // 创建一个新的 Drawable，并设置颜色
        Drawable drawable = context.getDrawable(drawableResId);
        Objects.requireNonNull(drawable).setColorFilter(color, PorterDuff.Mode.SRC_IN);
        // 设置 Drawable 大小
        drawable.setBounds(0, 0, 60, 60);
        // 设置 TextView 的背景为新的 Drawable
        textView.setCompoundDrawables(drawable, null, null, null);
    }


}
